#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

int n;
int ans[10000];
int tot;

int yes(int a)
{
    int i, rest, len;
    rest=0;
    len=0;
    do
    {
    	rest=rest*10+1;
    	++len;
    	rest%=a;
   	}while (rest!=0);
    return len;
    
}    

int main()
{
	int i, sum;

	

	memset(ans, 0, sizeof(ans));
	tot=0;
	for (i=1; i<10000; i+=2)
	{
	    if (i%5==0) continue;
	   	ans[i]=yes(i);
	}   

	while (scanf("%d",&n)!=EOF)
	{
     	printf("%d\n", ans[n]);
	}    
	
    
    return 0;
}    